<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width=" ">
      <el-form-item label="订单项id" prop="orderItemId">
        <el-input v-model="queryParams.orderItemId" placeholder="请输入订单项id" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="商品id" prop="goodsId">
        <el-input v-model="queryParams.goodsId" placeholder="请输入商品id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="评价视频地址信息" prop="evaluateVideo">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.evaluateVideo"-->
      <!--          placeholder="请输入评价视频地址信息"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="评价时间" prop="evaluateTime">
        <el-date-picker clearable v-model="queryParams.evaluateTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择评价时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="删除标识" prop="isDel">
        <template slot="label">
          <span>
            删除标识
            <el-tooltip class="item" effect="dark" content="0-正常，1-停用" placement="top">
              <i class="el-icon-question"></i>
            </el-tooltip>
          </span>
        </template>
        <el-input v-model="queryParams.isDel" clearable placeholder="请输入删除标识" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="删除标识"  prop="isDel">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.isDel"-->
      <!--          placeholder="请输入删除标识（0正常，1停用）"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段1" prop="ext1">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext1"-->
      <!--          placeholder="请输入扩展字段1"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段2" prop="ext2">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext2"-->
      <!--          placeholder="请输入扩展字段2"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段3" prop="ext3">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext3"-->
      <!--          placeholder="请输入扩展字段3"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段4" prop="ext4">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext4"-->
      <!--          placeholder="请输入扩展字段4"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段5" prop="ext5">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext5"-->
      <!--          placeholder="请输入扩展字段5"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
    </el-form>

    <el-row :gutter="10" class="mb8" style="display: flex;">
      <el-col style="justify-content: left;" :span="20">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:goodsEvaluate:add']">新增</el-button>
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:goodsEvaluate:edit']">修改</el-button>
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:goodsEvaluate:remove']">删除</el-button>
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:goodsEvaluate:export']">导出</el-button>
      </el-col>
      <el-col style="justify-content: right;" class="text-right" v-show="showSearch" :span="2.5">
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :span="1.5"></right-toolbar>
    </el-row>


    <el-table v-loading="loading" :data="goodsEvaluateList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="评价id" align="center" prop="evaluateId" />
      <el-table-column label="订单项id" align="center" prop="orderItemId" />
      <el-table-column label="商品id" align="center" prop="goodsId" />
      <el-table-column label="商品规格" align="center" prop="stander" />
      <el-table-column label="评价类型" align="center" prop="evaluateType" />
      <el-table-column label="评价内容" align="center" width="150" prop="evaluateContent" />
      <el-table-column label="评价图片" align="center" width="150" prop="evaluateImage">
        <template slot-scope="scope">
          <p v-if="scope.row.evaluateImage === null">无图片</p>
          <image-preview v-if="scope.row.evaluateImage !== null" :src="scope.row.evaluateImage" :width="50"
            :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="评价视频" align="center" width="150" prop="evaluateVideo">
        <template slot-scope="scope">
          <p v-if="scope.row.evaluateVideo === null || scope.row.evaluateVideo === ''">无视频</p>
          <div v-if="scope.row.evaluateVideo !== null && scope.row.evaluateVideo !== ''">
            <div v-for="(path, index) in scope.row.evaluateVideo.split(',')" :key="index">
              <el-link :href="api + path.trim()" target="_blank">视频{{ index + 1 }} : {{
                api + path.trim() }}</el-link>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="评价时间" align="center" prop="evaluateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.evaluateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="删除标识" align="center" prop="isDel" />
      <!--      <el-table-column label="扩展字段1" align="center" prop="ext1" />-->
      <!--      <el-table-column label="扩展字段2" align="center" prop="ext2" />-->
      <!--      <el-table-column label="扩展字段3" align="center" prop="ext3" />-->
      <!--      <el-table-column label="扩展字段4" align="center" prop="ext4" />-->
      <!-- <el-table-column label="创建时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)"
            v-hasPermi="['monitor:job:query']">详细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改商品评价管理对话框 -->
    <el-dialog :title="title" :visible.sync="openEdit" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="评价id" prop="evaluateId">
          <el-input v-model="form.evaluateId" placeholder="评价id自动生成，不必填写" readonly />
        </el-form-item>
        <el-form-item label="订单项id" prop="orderItemId">
          <el-input v-model="form.orderItemId" placeholder="请输入订单项id" />
        </el-form-item>
        <el-form-item label="商品id" prop="goodsId">
          <el-input v-model="form.goodsId" placeholder="请输入商品id" />
        </el-form-item>
        <el-form-item label="商品规格" prop="stander">
          <el-input v-model="form.stander" placeholder="请输入商品规格" />
        </el-form-item>
        <el-form-item label="评价内容">
          <el-input v-model="form.evaluateContent" placeholder="请输入评价内容" />
        </el-form-item>
        <el-form-item label="评价图片" prop="evaluateImage">
          <image-evaluate-upload v-model="form.evaluateImage" />
        </el-form-item>
        <el-form-item label="评价视频" prop="evaluateVideo">
          <file-evaluate-upload v-model="form.evaluateVideo" />
        </el-form-item>
        <el-form-item label="评价时间" prop="evaluateTime">
          <el-date-picker clearable v-model="form.evaluateTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择评价时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标识" prop="isDel">
          <template slot="label">
            <span>
              删除标识
              <el-tooltip class="item" effect="dark" content="0-正常，1-停用" placement="top">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </span>
          </template>
          <el-input v-model="form.isDel" placeholder="请输入删除标识（0-正常，1-停用）" />
        </el-form-item>
        <!--        <el-form-item label="扩展字段1" prop="ext1">-->
        <!--          <el-input v-model="form.ext1" placeholder="请输入扩展字段1" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段2" prop="ext2">-->
        <!--          <el-input v-model="form.ext2" placeholder="请输入扩展字段2" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段3" prop="ext3">-->
        <!--          <el-input v-model="form.ext3" placeholder="请输入扩展字段3" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段4" prop="ext4">-->
        <!--          <el-input v-model="form.ext4" placeholder="请输入扩展字段4" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段5" prop="ext5">-->
        <!--          <el-input v-model="form.ext5" placeholder="请输入扩展字段5" />-->
        <!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="openView" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="评价id" prop="evaluateId">
          <el-input v-model="form.evaluateId" placeholder="评价id自动生成，不必填写" readonly />
        </el-form-item>
        <el-form-item label="订单id" prop="orderId">
          <el-input v-model="form.orderId" placeholder="未填入订单id" readonly />
        </el-form-item>
        <el-form-item label="商品id" prop="goodsId">
          <el-input v-model="form.goodsId" placeholder="未填入商品id" readonly />
        </el-form-item>
        <el-form-item label="商品名称" prop="goodsName">
          <el-input v-model="form.goodsName" placeholder="未填入商品名称" readonly />
        </el-form-item>
        <el-form-item label="商品规格" prop="stander">
          <el-input v-model="form.stander" placeholder="未填入商品规格" readonly />
        </el-form-item>
        <el-form-item label="评价内容">
          <el-input v-model="form.evaluateContent" placeholder="未填入评价内容" readonly />
        </el-form-item>
        <el-form-item label="评价图片" prop="evaluateImage">
          <template slot-scope="scope">
            <p v-if="form.evaluateImage === null">无图片</p>
            <image-preview v-if="form.evaluateImage !== null" :src="form.evaluateImage" :width="50"
              :height="50" />
          </template>
        </el-form-item>
        <el-form-item label="评价视频" prop="evaluateVideo">
          <file-evaluate-upload v-model="form.evaluateVideo" readonly />
        </el-form-item>
        <el-form-item label="评价时间" prop="evaluateTime">
          <el-date-picker clearable v-model="form.evaluateTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="未填入评价时间" readonly>
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标识" prop="isDel">
          <template slot="label">
            <span>
              删除标识
              <el-tooltip class="item" effect="dark" content="0-正常，1-停用" placement="top">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </span>
          </template>
          <el-input v-model="form.isDel" placeholder="未填入删除标识（0-正常，1-停用）" readonly />
        </el-form-item>
        <!--        <el-form-item label="扩展字段1" prop="ext1">-->
        <!--          <el-input v-model="form.ext1" placeholder="请输入扩展字段1" readonly/>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段2" prop="ext2">-->
        <!--          <el-input v-model="form.ext2" placeholder="请输入扩展字段2" readonly/>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段3" prop="ext3">-->
        <!--          <el-input v-model="form.ext3" placeholder="请输入扩展字段3" readonly/>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段4" prop="ext4">-->
        <!--          <el-input v-model="form.ext4" placeholder="请输入扩展字段4" readonly/>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段5" prop="ext5">-->
        <!--          <el-input v-model="form.ext5" placeholder="请输入扩展字段5" readonly/>-->
        <!--        </el-form-item>-->
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listGoodsEvaluate, getGoodsEvaluate, delGoodsEvaluate, addGoodsEvaluate, updateGoodsEvaluate } from "@/api/system/goodsEvaluate";
import { getGoods } from "@/api/system/goods";

export default {
  name: "GoodsEvaluate",
  data() {
    return {
      api: `${process.env.VUE_APP_BASE_API}`,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品评价管理表格数据
      goodsEvaluateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      openEdit: false,
      openView: false,
      // 表格数据
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderItemId: null,
        goodsId: null,
        stander: null,
        evaluateType: null,
        evaluateContent: null,
        evaluateImage: null,
        evaluateVideo: null,
        evaluateTime: null,
        isDel: null,
        ext1: null,
        ext2: null,
        ext3: null,
        ext4: null,
        ext5: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商品评价管理列表 */
    async getList() {
      this.loading = true;
      const response = await listGoodsEvaluate(this.queryParams)
      this.goodsEvaluateList = response.rows;
      this.total = response.total;
      await this.updateGoodsName();
      this.loading = false;
    },
    // 新增元素商品名称
    async updateGoodsName() {
      for (let i = 0; i < this.goodsEvaluateList.length; i++) {
        let good = await getGoods(this.goodsEvaluateList[i].goodsId);
        this.$set(this.goodsEvaluateList[i], 'goodsName', good.data.goodsName);
      }
    },
    // 取消按钮
    cancel() {
      this.openEdit = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        evaluateId: null,
        orderItemId: null,
        goodsId: null,
        stander: null,
        evaluateType: null,
        evaluateContent: null,
        evaluateImage: null,
        evaluateVideo: null,
        evaluateTime: null,
        isDel: null,
        createTime: null,
        updateTime: null,
        ext1: null,
        ext2: null,
        ext3: null,
        ext4: null,
        ext5: null
      };
      this.resetForm("form");
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.openView = true;
      this.form = row;
      this.title = "商品评价管理详细（如需修改，请通过修改按钮进行修改）";
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.evaluateId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openEdit = true;
      this.title = "添加商品评价管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const evaluateId = row.evaluateId || this.ids
      getGoodsEvaluate(evaluateId).then(response => {
        this.form = response.data;
        this.openEdit = true;
        this.title = "修改商品评价管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.evaluateId != null) {
            updateGoodsEvaluate(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openEdit = false;
              this.getList();
            });
          } else {
            addGoodsEvaluate(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openEdit = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const evaluateIds = row.evaluateId || this.ids;
      this.$modal.confirm('是否确认删除商品评价管理Id为"' + evaluateIds + '"的数据项？').then(function () {
        return delGoodsEvaluate(evaluateIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/goodsEvaluate/export', {
        ...this.queryParams
      }, `goodsEvaluate_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
